<template>
    <view class="content">
        <view class="search">
            <view class="s-left">省市区</view>
            <view class="s-inp" @click="regionShow = true">
                <input type="text" v-model="keyword" class="inp" disabled>
                <u-icon name="arrow-down-fill" color="#575757" size="24" class="u-m-l-10"></u-icon>
            </view>
        </view>
        
        <view class="nav">
            <view class="nav-i" :class="{active : type == 1}" @click="chooseNav(1)">招聘</view>
            <view class="nav-i" :class="{active : type == 2}" @click="chooseNav(2)">求职</view>
            <view class="nav-i" :class="{active : type == 3}" @click="chooseNav(3)">出租/出售</view>
            <view class="nav-i" :class="{active : type == 4}" @click="chooseNav(4)">求租/求购</view>
            <view class="nav-i" :class="{active : type == 5}" @click="chooseNav(5)">其他</view>
        </view>
        <view class="item item-d u-p-t-40" v-if="type == 1 || type == 2" v-for="(item, index) in list" :key="index"
            @click="$gTo(`/pages/people/detail?id=${item.id}`)">
            <view class="top2">
                <view class="title">{{item.title}}</view>
                <view class="sta">{{item.type_txt}}</view>
            </view>
            <view class="price">{{item.salary}}</view>
            <view class="name">
                {{item.contacts}} <text class="u-p-l-15">{{item.telephone}}</text>
            </view>
            <view class="down">
                <view @click.stop="goTel(item.telephone)">
                    <image src="../../static/icon/tel2.png" class="tel2"></image>
                    <view>电话</view>
                </view>
            </view>
        </view>
        
        <view class="item" v-else v-for="(item, index) in list" :key="index" 
            @click="$gTo(`/pages/people/site-detail?id=${item.id}`)">
            <view>
                <image src="../../static/image/g_img_1.png" class="img-1" v-if="item.member_type_txt == '个人'"></image>
                <image src="../../static/image/g_img_2.png" class="img-1" v-else></image>
            </view>
            <view class="item-d">
                <view class="top2">
                    <view class="title">{{item.title}}</view>
                    <view class="sta">{{item.type_txt}}</view>
                    <!-- <view class="sta sta2">求购</view> -->
                </view>
                <view class="text">{{item.describe}}</view>
                <view class="img-box" v-if="item.image_uri_txt.length > 0">
                    <view class="u-rela" v-for="(el, ind) in item.image_uri_txt" :key="ind" v-if="ind < 3">
                        <image :src="el.attach_uri" class="img"></image>
                        <view class="img-num" v-if="item.image_uri_txt.length > 3 && ind == 2">+{{ item.image_uri_txt.length - 3 }}</view>
                    </view>
                </view>
                <view class="down">
                    <view @click.stop="goTel(item.telephone)">
                        <image src="../../static/icon/tel2.png" class="tel2"></image>
                        <view>电话</view>
                    </view>
                </view>
            </view>
        </view>
        
        <view style="height: 94rpx;padding-top: 30rpx;">
            <u-loadmore :status="status" v-if="status != 'loadmore'" />
        </view>
        
        <view class="footer" @click="add">发布信息</view>
        
        <!-- 省市区 -->
        <u-select v-model="regionShow" mode="mutil-column-auto" :list="region" value-name="region_id" label-name="name" child-name="sub" 
            @confirm="confirm"></u-select>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                regionShow: false,
                region: [],
                keyword: '请选择',
                province: '',
                city: '',
                district: '',
                status: 'loadmore', //是否显示没有更多了
                page: 1,
                list: [],
                type: 1,
            };
        },
        onLoad() {
			this.keyword = '内蒙古自治区/通辽市'
			this.province = 150000
			this.city = 150500
            this.getRegion()
        },
        onShow() {
            this.list = []
            this.page = 1
            this.status = 'loadmore'
            this.getList()
        },
        onReachBottom() {
        	if(this.page == 1){return}
        	this.getList()
        },
        methods: {
			add() {
				if (!uni.getStorageSync('userToken')) {
				    this.$confirm('请先登录并且绑定手机号，是否去登录？',()=>{
				        uni.navigateTo({
				            url: "/pages/login/login"
				        })
				    })
				} else {
					this.$gTo(`/pages/people/create`)
				}
			},
			
			goTel(t) {
				this.$call(t)
			},
			
            chooseNav(num) {
                if (this.type == num) return
                this.type = num
                this.list = []
                this.page = 1
                this.status = 'loadmore'
                this.getList()
            },
            
            getList() {
            	if (this.status == 'nomore') return;
            	this.status = 'loading';
            	this.$ajax('LnformationList', {
            		userToken: this.$getSync('userToken'),
            		page: this.page,
            		limit: 10,
                    category: 2,//1-牛源信息 2-人力场地信息
                    type: this.type,//category=1的时候type 1-出售 2-是求购，category=2的时候 type是 1-招聘 2-求职 3-出租/出售 4-求租/求购 5-其他
                    gender: '',//公牛/母牛 男/女
                    province: this.province,
                    city: this.city,
                    district: this.district,
            	}).then(ret => {
            		if (ret.status == 0) {
            			if (ret.data.list.length > 0) {
            				this.list = this.list.concat(ret.data.list);
            				this.page++;
            				this.status = 'loadmore'
            			} else {
            				this.status = 'nomore'
            			}
            		} else {
            			this.$toast(ret.message);
            		}
            	});
            },
            
            // 选择省市区
            confirm(e) {
                console.log(e);
                this.keyword = e[0].label + e[1].label + e[2].label
                this.province = e[0].value
                this.city = e[1].value
                this.district = e[2].value
                
                this.list = []
                this.page = 1
                this.status = 'loadmore'
                this.getList()
            },
            
            // 获取省市区
            getRegion(){
            	this.$ajax('region', {
            		
            	}).then(ret => {
            		if (ret.status == 0) {
            			this.region = ret.data
            		} else {
            			this.$toast(ret.message);
            		}
            	});
            },
        }
    };
</script>

<style lang="scss">
    
    
    page{
        background-color: #f5f5f5;
    }
    .content{
        padding: 20rpx 0 100px;
    }
    .search{
        display: flex;
        justify-content: space-between;
        align-items: center;
        font-size: 26rpx;
        margin-bottom: 20rpx;
        padding: 0 20rpx;
    }
    .s-left{
        color: #737373;
        padding-right: 20rpx;
    }
    .s-inp{
        flex: 1;
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 15rpx;
        background-color: #fff;
        border-radius: 15rpx;
    }
    .inp{
        flex: 1;
    }
    .screen{
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding-left: 25rpx;
    }
    .screen-icon{
        width: 26rpx;
        height: 21rpx;
        margin-right: 5rpx;
    }
    
    
    .nav{
        background-color: #fff;
        display: flex;
        justify-content: flex-start;
        align-items: center;
        margin-bottom: 20rpx;
    }
    .nav-i{
        width: calc(100vw / 5);
        padding: 30rpx 0;
        text-align: center;
    }
    .active{
        font-size: 32rpx;
        color: #00734c;
        border-bottom: 2rpx solid #00734c;
    }
    
    
    .item{
        background-color: #fff;
        border-radius: 15rpx;
        margin: 0 20rpx 20rpx;
    }
    .img-1{
        width: 90rpx;
        height: 42rpx;
    }
    .item-d{
        padding: 10rpx 30rpx 30rpx;
    }
    .top2{
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    .title{
        font-size: 34rpx;
        font-weight: bold;
        word-break: break-all;
        white-space: pre-line;
        padding-right: 15rpx;
    }
    .sta{
        padding: 4rpx 15rpx;
        border-radius: 6rpx;
        font-size: 23rpx;
        color: #ff5f2b;
        background-color: #fff1ec;
    }
    .sta2{
        color: #0075ff;
        background-color: #dfeeff;
    }
    .text{
        font-size: 28rpx;
        word-break: break-all;
        white-space: pre-line;
        padding-top: 15rpx;
    }
    .img-box{
        display: flex;
        justify-content: flex-start;
        align-items: center;
        padding-top: 10rpx;
    }
    .img{
        width: 200rpx;
        height: 200rpx;
        border: 2rpx solid #dedede;
        border-radius: 10rpx;
        margin-right: 20rpx;
        box-sizing: border-box;
    }
    .img:nth-child(3n) {
        margin-right: 0;
    }
    .img-num{
        font-size: 26rpx;
        color: #fff;
        text-align: center;
        line-height: 200rpx;
        width: 200rpx;
        height: 200rpx;
        border-radius: 10rpx;
        background: rgba(0, 0, 0, .5);
        position: absolute;
        left: 0;
        top: 0;
        z-index: 1;
    }
    .down{
        font-size: 26rpx;
        color: #595b62;
        padding-top: 20rpx;
        display: flex;
        justify-content: flex-end;
        align-items: center;
    }
    .down>view{
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding-left: 50rpx;
    }
    .tel2{
        width: 27rpx;
        height: 27rpx;
        margin-right: 10rpx;
    }
    
    .price{
        font-size: 32rpx;
        font-weight: bold;
        color: #f62a2a;
        padding: 10rpx 0;
    }
    .name{
        font-size: 26rpx;
        color: #595b62;
    }
    
    .footer{
        width: 100%;
        height: 90rpx;
        background-color: #00734c;
        font-size: 36rpx;
        color: #fff;
        text-align: center;
        line-height: 90rpx;
        position: fixed;
        left: 0;
        bottom: 0;
        z-index: 9;
    }
    
    
    .popup{
        display: flex;
        flex-direction: column;
        justify-content: space-between;
    }
    .pop{
        padding: 0 30rpx;
    }
    .p-tit{
        font-size: 32rpx;
        font-weight: bold;
        padding: 20rpx 0;
    }
    .p-box{
        display: flex;
        flex-wrap: wrap;
        justify-content: flex-start;
        align-items: center;
    }
    .p-item{
        font-size: 26rpx;
        padding: 20rpx 50rpx;
        background-color: #f5f5f5;
        border-radius: 15rpx;
        margin-right: 15rpx;
        margin-bottom: 15rpx;
    }
    .pActive{
        color: #083d2b;
        border: 2rpx solid #083d2b;
        background-color: #d6ebe4;
        box-sizing: border-box;
    }
    .p-btns{
        height: 7vh;
        background-color: #ff8a00;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    .p-btn{
        width: calc(588rpx / 2);
        font-size: 30rpx;
        color: #fff;
        text-align: center;
    }
    .p-line{
        width: 2rpx;
        height: 37rpx;
        background-color: #fff;
    }

</style>
